
CREATE TABLE "ChargeModuleTemplate" (
	"ChargeModuleTemplateId" serial4 NOT NULL,
	"StartDate" timestamp NULL,
	"EndDate" timestamp NULL,
	"Active" bool NULL DEFAULT true,
	"TemplateName" text NULL,
	"CreatedBy" int4 NULL,
	"CreatedDate" timestamp NULL,
	"ModifiedBy" int4 NULL,
	"ModifiedDate" timestamp NULL,
	"LocationId" int4 NULL,
	CONSTRAINT "ChargeModuleTemplate_pkey" PRIMARY KEY ("ChargeModuleTemplateId"),
	CONSTRAINT "ChargeModuleTemplate_CreatedBy_fkey" FOREIGN KEY ("CreatedBy") REFERENCES "Account"("AccountId"),
	CONSTRAINT "ChargeModuleTemplate_LocationId_fkey" FOREIGN KEY ("LocationId") REFERENCES "Location"("LocationId"),
	CONSTRAINT "ChargeModuleTemplate_ModifiedBy_fkey" FOREIGN KEY ("ModifiedBy") REFERENCES "Account"("AccountId")
);

-----------------------


CREATE TABLE "ChargeModuleCategory" (
	"ChargeModuleCategoryId" serial4 NOT NULL,
	"Active" bool NULL DEFAULT true,
	"ChargeCategoryId" int4 NULL,
	"ModulesMasterId" int4 NULL,
	"ChargeModuleTemplateId" int4 NULL,
	"CreatedBy" int references "Account"("AccountId"),
			"CreatedDate" timestamp,
			"ModifiedBy" int references "Account"("AccountId"),
			"ModifiedDate" timestamp,
	CONSTRAINT "ChargeModuleCategory_pkey" PRIMARY KEY ("ChargeModuleCategoryId"),
	CONSTRAINT "ChargeModuleCategory_ChargeCategoryId_fkey" FOREIGN KEY ("ChargeCategoryId") REFERENCES "ChargeCategory"("ChargeCategoryId"),
	CONSTRAINT "ChargeModuleCategory_ChargeModuleTemplateId_fkey" FOREIGN KEY ("ChargeModuleTemplateId") REFERENCES "ChargeModuleTemplate"("ChargeModuleTemplateId"),
	CONSTRAINT "ChargeModuleCategory_ModulesMasterId_fkey" FOREIGN KEY ("ModulesMasterId") REFERENCES "ModulesMaster"("ModulesMasterId")
);
-------------
create table "ChargeModuleDetails"(
			"ChargeModuleDetailsId" bigserial primary key,
			"ReferenceId" int not null,
			"ChargeModuleCategoryId" int references "ChargeModuleCategory"("ChargeModuleCategoryId"),
			"Amount" numeric(10,2),
			"LocationId" int references "Location"("LocationId"),
			"CreatedBy" int references "Account"("AccountId"),
			"CreatedDate" timestamp,
			"ModifiedBy" int references "Account"("AccountId"),
			"ModifiedDate" timestamp
);

--------------------

alter table "ChargeModuleTemplate" add column "IsInUse" boolean default false;

------------------
